<template>
	<view>
		<view v-if="tracesData.length <= 0 " class="reason">
			{{reason}}
		</view>
		<view v-else>
			<!-- <view class="logistic_id">
				<view style="padding: 20rpx 10rpx; font-size: 26rpx;">快递简称：{{info.ShipperCode}}</view>
			</view> -->
			<view class="logistic_id">
				<view style="padding: 20rpx 10rpx; font-size: 26rpx;">快递单号：{{info.LogisticCode||logisticInfos[0].logisticNumber}}</view>
				<view class="copybox" @click="copy(info.LogisticCode||logisticInfos[0].logisticNumber)">复制</view>
			</view>
			<block v-for="(item, index) in tracesData" :key="index">
				<xxlogistics :is-first="index===tracesData.length-1" :is-newest="index===0"  v-if="infos.store_id == 32"
					:is-main-node="item.isMainNode" :node-data="item"></xxlogistics>
				<trackNode :is-first="index===tracesData.length-1" :is-newest="index===0" v-else
					:is-main-node="item.isMainNode" :node-data="item"></trackNode>
			</block>
		</view>
	</view>
</template>

<script>
	import trackNode from '../../components/trackNode.vue'
	import xxlogistics from '../../components/xxlogistics.vue'
	export default {
		components: {
			trackNode,
			xxlogistics
		},
		async onLoad(option) {
			this.infos = JSON.parse(decodeURIComponent(option.info))
			// this.$http({
			// 	url:'api/poss_api/logistics',
			// 	data:{orderid:option.orderid}
			// }).then(res=>{
			// 	console.log(res.data.data)
			// 	 this.tracesData = res.data 
			// })
			console.log(this.infos, 'infos')
			if (this.infos.store_id == 32) {
				await this.$http({
					url: 'api/Xiaoxiang/getOrderDelivery',
					data: {
						orderItemId: this.infos.orderItem[0].orderItemId
					}
				}).then(res => {
					this.tracesData = res.data.trackInfos
					this.logisticInfos = res.data.logisticInfos
				})

			} else {
				await this.$http({
					url: 'api/Wechat/queryLogistic',
					data: {
						orderid: this.infos.id
					}
				}).then(res=>{
					console.log(res, 'res')
					this.tracesData = res.data.Traces
					// this.tracesData = data.reverse();
					// console.log(this.tracesData,'this.tracesData',Traces)
					// this.reason = nu + '...'
					this.reason = res.data.Reason
					this.info = res.data
				})
				
			}

			// const {data: {data,nu}} = await this.$http({url: 'api/order/queryLogistic',data: {id:option.id}});
			

			// this.LogisticCode= data.data.LogisticCode
		},
		data() {
			return {
				reason: '',
				infos: {},
				info: '', //快递单号
				logisticInfos:[],
				tracesData: [
					// {
					//   acceptStation: '包裹已被吴亦发同学签收', // 节点描述
					//   createTime: '2019-10-24 15: 27: 16',
					//   status: 'COMPLETE', // 节点状态
					//   phone: '', // 电话
					//   statusName: '已签收', // 节点标题
					//   isMainNode: true // 是否主节点，主节点前方展示icon
					// },
					// {
					//   acceptStation: '由派送员蔡小坤同志配送，电话：',
					//   createTime: '2019-10-24 15: 26: 41',
					//   status: 'DELIVERING',
					//   phone: '16677778888',
					//   statusName: '运输中',
					//   isMainNode: true
					// },
					// {
					//   acceptStation: '已到XXX小区快递点',
					//   createTime: '2019-10-24 15: 26: 41',
					//   status: 'DELIVERING',
					//   phone: '',
					//   statusName: '运输中',
					//   isMainNode: false
					// },
					// {
					//   acceptStation: '已到海宁集散中心',
					//   createTime: '2019-10-24 15: 26: 18',
					//   status: 'DELIVERING',
					//   phone: '',
					//   statusName: '运输中',
					//   isMainNode: false
					// },
					// {
					//   acceptStation: '已到杭州集散中心',
					//   createTime: '2019-10-24 15: 26: 07',
					//   status: 'DELIVERING',
					//   phone: '',
					//   statusName: '运输中',
					//   isMainNode: false
					// },
					// {
					//   acceptStation: '包裹已到达余杭区集散中心',
					//   createTime: '2019-10-24 15: 25: 54',
					//   status: 'DELIVERING',
					//   phone: '',
					//   statusName: '运输中',
					//   isMainNode: false
					// },
					// {
					//   acceptStation: '快递员已上门取件',
					//   createTime: '2019-10-24 15: 25: 17',
					//   status: 'DELIVERING',
					//   phone: '',
					//   statusName: '已揽收',
					//   isMainNode: false
					// },
					// {
					//   acceptStation: '等待快递员上门揽件',
					//   createTime: '2019-10-24 15: 25: 00',
					//   status: 'WATTING_DELIVER',
					//   phone: '',
					//   statusName: '已发货',
					//   isMainNode: true
					// },
					// {
					//   acceptStation: '您的包裹正在打包',
					//   createTime: '2019-10-24 15: 24: 00',
					//   status: 'WATTING_DELIVER',
					//   phone: '',
					//   statusName: '待发货',
					//   isMainNode: false
					// },
					// {
					//   acceptStation: '订单支付成功，等待商家发货',
					//   createTime: '2019-10-24 15: 22: 30',
					//   status: 'PAYED',
					//   statusName: '已支付',
					//   isMainNode: true
					// },
					// {
					//   acceptStation: '订单提交成功',
					//   createTime: '2019-10-24 15: 22: 00',
					//   status: 'WATTING_PAY',
					//   statusName: '已下单',
					//   isMainNode: true
					// }
				]
			}
		},
		methods: {
			//复制快递单号
			copy(value) {
				// 复制指定内容
				uni.setClipboardData({
					data: value,
					success() {
						uni.showToast({
							title: '复制成功',
							icon: 'none'
						})
					}
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.reason {
		position: fixed;
		top: 50%;
		left: 50%;
		transform: translate(-50%, -50%);
	}

	.logistic_id {
		display: flex;
		justify-content: space-between;
		align-items: center;

		.copybox {
			width: fit-content;
			padding: 0 30rpx;
			height: 42rpx;
			font-size: 26rpx;
			color: #666666;
		}
	}
</style>